package edu.ccut.saturn.authority.impl.department;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import edu.ccut.saturn.component.DefaultSaturnValidate;
import edu.ccut.saturn.component.ValidateResult;

public class ValidateDept extends DefaultSaturnValidate {

	protected void doValidate(Object value, Object[] args,
			ValidateResult result) {
		String valueStr  =(String )value;
		Connection conn = getConnection();
		Statement stat = null;
		ResultSet rs = null;
		String sql ="select * from saturn_authority_department where id ='"+valueStr+"'"; 
		try {
			stat = conn.createStatement();
			rs = stat.executeQuery(sql);
			if(rs.next()){
				result.addValidateError("\u6b64\u673a\u6784ID\u5df2\u7ecf\u88ab\u5360\u7528", value); 
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				if(rs!=null){
					rs.close();
				}
				if(stat!=null){
					stat.close();
				}
				if(conn != null){
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}